﻿var UranusWei = angular.module("UranusWei");

UranusWei.controller("main", ['$scope', '$rootScope', 'uranusPlus', 'commonFactory', 'CacheFactory', '$timeout', 'appconfig','$interval', function ($scope, $rootScope, uranusPlus, commonFactory, CacheFactory, $timeout, appconfig ,$interval) {
    $rootScope.Template = {
        showbackicon: false,
        showheader: false
    }
    var isapp = CacheFactory.getH5Storage("isapp");
    if (isapp == "1" || isapp == "2") {
    } else {
        CacheFactory.setH5Storage("isapp", "1");
    }
    uranusPlus.init(function () {
        plus.navigator.setStatusBarBackground("#FFFFFF");
        plus.navigator.setStatusBarStyle('dark');
        $scope.appid = plus.runtime.appid;
        plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) {
            wgtinfo.version = wgtinfo.version.replace(/\./g, '')
            if (wgtinfo.version >= 320 && commonFactory.versions.android || $scope.appid == 'com.youliyoucaiapp.ios') {
                uranusPlus.Share.updateShareSerivces();
            }
        });

        CacheFactory.setH5Storage("isapp", "2");
        $rootScope.isApp = uranusPlus.isApp;
        if (!$rootScope.appinitsuccess) {/*验证是否关闭启动界面*/
            $timeout(function () {
                plus.webview.getLaunchWebview().evalJS("InitComplete()");
                plus.navigator.setStatusBarBackground("#FFFFFF");
                $rootScope.appinitsuccess = true;
            }, plus.runtime.launchLoadedTime + 500);
        }      
    });
    var initdata = function () {
        commonFactory.ajax("/api/version/GetVersion", {}, function (result) {//版本更新弹出框
            if (result.code == 1) {
                var data = result.data
                if (data) {
                    $rootScope.webversion = data.code
                    if (appconfig.version < data.code && data.isDialog) {
                        $scope.vercon = data.content;
                        var upDvar = document.querySelector('#upDvar')
                        if(upDvar.style.display == 'none'){
                           upDvar.style.display = 'block';
                        }       
                    } else if (appconfig.version < data.code && !data.isDialog) {
                        window.location.reload()
                    }
                }
            } else if (result.code == 8) {
                commonFactory.gologin();
            }
        }, function () {

        }, "get");
        // //请求未读消息数量
        commonFactory.ajax("/api/Product/GetNoReadPlusAndRed", {}, function (result) {
            if (result.data != null) {
                $scope.TotalNumber = result.data.totalNumber;
                $scope.PlusNumber = result.data.plusNumber;
                $scope.RedNumber = result.data.redNumber;
            } else {
                $scope.TotalNumber = 0;
                $scope.PlusNumber = 0;
                $scope.RedNumber = 0;
            }
        }, function () { }, "post");
        // 请求红包加息券总数量
        commonFactory.ajax("/api/Product/GetRedAndPlusNumber", {}, function (result) {
            if (result.data != null) {
                $scope.redpacketNum = result.data.redNumber;
                $scope.ratecouponNum = result.data.plusNumber;
            } else {
                $scope.redpacketNum = 0;
                $scope.ratecouponNum = 0;
            }
        }, null, "post")
    }
    initdata();
    // 有利福利跳转设置
    $scope.youliwealClick = function () {
        // 如果加息券和红包数量为0，跳转到体验金
        if ($scope.ratecouponNum == 0 && $scope.redpacketNum == 0) {
            commonFactory.go("/mine/youliweal/experience");
        } else if ($scope.ratecouponNum == 0 && $scope.redpacketNum > 0) {
            commonFactory.go("/mine/youliweal/redpacket");
        } else if ($scope.PlusNumber == 0 && $scope.RedNumber > 0) {
            commonFactory.go("/mine/youliweal/redpacket");
        } else {
            commonFactory.go("/mine/youliweal/ratecoupon");
        }
    }
    $scope.mainHome = function () {
        commonFactory.go('/main/home');
        initdata()
    }
    $scope.mainday = function () {
        commonFactory.go('/main/day');
        initdata()
    }
    $scope.mainList = function () {
        commonFactory.go('/main/list');
        initdata()
    }
    $scope.mainMine = function () {
        $scope.user = CacheFactory.getUser();
        if (!$scope.user) {//检测登录
            commonFactory.gologin();
            return;
        }
        commonFactory.go('/main/mine');
        initdata();
    }
}]);
/* 精选页 */
UranusWei.controller("mainhome", ['$scope', '$rootScope', 'uranusiscroll', 'commonFactory', 'appconfig', '$timeout', 'CacheFactory', 'uranusPlus', '$interval', function ($scope, $rootScope, uranusiscroll, commonFactory, appconfig, $timeout, CacheFactory, uranusPlus, $interval) {
    $rootScope.Template = {
        title: '有利金服',
        state: 'mainhome',
        showbackicon: false,
        showheader: false
    }
    var dthis = new uranusiscroll();
    var text = commonFactory.GetRandomPullAd();
    dthis.showtext({ downtext: text, opentext: text, loadingtext: text });
    uranusiscroll = dthis.init(false, false);
    var loadingArr = [], loadingCount = 1;
    // var isapp = CacheFactory.getH5Storage("isapp");
    var initdata = function () {
        $scope.goshare = function () {
            commonFactory.ajax("/api/Share/MyShareStatistics", {}, function (result) {
                if (result.code == 1) {
                    if (result.data.bonuses && result.data.firends || result.data.bonuses) {
                        commonFactory.go('/mine/invitebonus/bonusdetail')
                    } else if (result.data.firends) {
                        commonFactory.go('/mine/invitebonus/friendlist')
                    } else {
                        commonFactory.go('/mine/invitebonus/bonusdetail')
                    }
                } else if (result.code == 8) {
                    commonFactory.gologin();
                }
            }, function () {

            }, "post");
        }
        commonFactory.initComplate(loadingArr, loadingCount, function () {
            if (appconfig.version >= $rootScope.webversion) {//当版本切换时 广告弹框关闭
                commonFactory.messageclose();
                if ($scope.adhtml && $scope.adhtml != "") {
                    var times = 300;
                    if (commonFactory.versions.ios) {
                        times = 300;
                    }
                    var addjs = $timeout(function () {
                        if ($scope.adhtml && $rootScope.Template.state == 'mainhome') {
                            commonFactory.messageview($scope.adhtml, { height: 1, width: 1, shadeClose: true, bgcolor: "transparent" }, $scope);
                        }
                    }, times);
                    $rootScope.djsArr.push(addjs);
                }
            }
            $timeout(function () {
                uranusiscroll.refresh();
            }, appconfig.pulldowntime);
        });
        uranusPlus.init(function () {
            plus.runtime.getProperty(plus.runtime.appid, function (wgtinfo) {
                //version属性
                $scope.wgtStr = wgtinfo.version;
            });
        });
        /* Banner图 */
        $scope.adInfo = [];
        $scope.radius = [];
        $scope.DevicesWidth = $rootScope.deviceInfo.width;
        $scope.active = false;
        $scope.adActive = false;
        var licai = JSON.stringify(window.location).indexOf('licai');//理财版去掉11888banner
        var auctionbannerproduct = $scope.auctionbannerproduct;
        var admoveid = 1;
        if (admoveid > 0) {
            var adlist = CacheFactory.getStorage("time_homeadlist-" + admoveid);
            if (adlist) {
                for (var i = 0; i < adlist.length; i++) {
                    if (i == 0) {
                        $scope.radius.push({ active: true });
                    }
                    else {
                        $scope.radius.push({ active: false });
                    }
                }
                $scope.adInfo = adlist;
            }
            commonFactory.ajax("/api/Ad/AdList", { typeid: admoveid, num: 10 }, function (result) {
                if (result.code == 1) {
                    for (var i = result.data.length - 1; i >= 0; i--) {
                        if (result.data[i].adImage == 'f9207c89a7b74a6c938343dc0cdc7b27.jpg' && licai != -1 && $scope.wgtStr == '3.0.1') {//理财版去掉11888banner
                            result.data.splice(i, 1);
                        }
                        for (var j = result.data.length - 1; j >= 0; j--) {
                            if (result.data[j].adImage && result.data[j].adImage != "") {
                                if (result.data[j].adImage.indexOf("http://") == -1 && result.data[j].adImage.indexOf("https://") == -1) {
                                    result.data[j].adImage = $rootScope.imgbaseurl + result.data[j].adImage;
                                }
                            }
                        }
                    }
                    if (result.data && result.data.length > 0) {
                        var sourcedata = result.data;
                        if (!commonFactory.comparisonobj(adlist, sourcedata)) {
                            if (sourcedata.length > 1) {
                                $scope.radius = [];
                                for (var i = 0; i < sourcedata.length; i++) {
                                    if (i == 0) {
                                        $scope.radius.push({ active: true });
                                    }
                                    else {
                                        $scope.radius.push({ active: false });
                                    }
                                }
                            }
                            $scope.adInfo = sourcedata;
                            CacheFactory.setStorage("time_homeadlist-" + admoveid, sourcedata, { isExpires: true, expiresTime: CacheFactory.hour * 48 });
                        }
                        $scope.adActive = true;
                    }
                }
            }, null, "post");
        }
        $scope.transitionEnd = function () {
            return function (sliderIndex) {
                var adInfo = $scope.adInfo;
                if (adInfo.length > 1) {
                    var radius = $scope.radius;
                    angular.forEach(radius, function (rad, i) {
                        rad.active = false;
                    });
                    if (sliderIndex == (adInfo.length - 1)) {
                        radius[0].active = true;
                    } else if (sliderIndex == 0) {
                        radius[adInfo.length - 2].active = true;
                    } else {
                        radius[sliderIndex - 1].active = true;
                    }
                    $scope.$apply();
                }
            }
        }
        $scope.godetail = function (loanPeriod, url) {
            if (loanPeriod) {
                $rootScope.go(url);
            } else {
                $rootScope.go('/day/currentdetail');
                uranusiscroll.refresh();
            }
        };
        var producthomearr = CacheFactory.getStorage("time_producthomearr")
        if (producthomearr) {
            $scope.producthomearr = producthomearr;
            $scope.active = true;
        }
        var cacheData = [];
        /*获取产品精选页*/
        var options = {
            storekey: "producthome",
            method: "post",
            setExpires: {
                isExpires: true,
                expiresTime: CacheFactory.hour * 48
            },
            callback: function (result) {
                if (result.code == 1) {
                    loadingArr.push("GetHomeProduct");
                    cacheData = result.data.productMainHomeList;
                    // $scope.active = false;
                }
            },
            url: "/api/product/GetProductMainHome",
            data: { size: 3 },
            callbacktwo: function (result) {
                if (loadingArr.indexOf("GetHomeProduct") == -1) {
                    commonFactory.messageloading({ process: true });
                    loadingArr.push("GetHomeProduct");
                }

                if (result.code == 1) {
                    for (i = 0; i < result.data.productMainHomeList.length; i++) {
                        var oStr = result.data.productMainHomeList[i].productName.search(/\d{3,}/);
                        if (oStr != '-1') {
                            var oData = result.data.productMainHomeList[i].productName.substring(0, oStr);
                            result.data.productMainHomeList[i].productName = oData.replace('-', '');
                        }
                    }
                    var newcacheData = result.data.productMainHomeList;

                    if (!commonFactory.comparisonobj(cacheData, newcacheData)) {
                        $scope.producthomearr = newcacheData;
                        CacheFactory.setStorage("time_producthomearr", newcacheData, { isExpires: true, expiresTime: CacheFactory.hour * 48 });
                        $scope.active = true;
                    }
                    uranusiscroll.refresh();
                }
            },
            err: function () {
                if (loadingArr.indexOf("GetHomeProduct") == -1) {
                    loadingArr.push("GetHomeProduct");
                }
                commonFactory.messageclose();
                uranusiscroll.refresh();
            }
        };
        // 按时显示
        var timeShow = function () {
            $scope.grayshow = false;
            var endhours = Number($scope.gethours) + parseInt((Number($scope.getMinutes) + Number($scope.thistime)) / 60)
            var endhminutes = Number($scope.getMinutes) + Number($scope.thistime)
            if (endhours >= 24) {
                endhours = endhours % 24
            }
            if (endhminutes >= 60) {
                endhminutes = endhminutes % 60
            }
            var countTime = function () {
                var hours = $scope.serviceTime.getHours();
                var minutes = $scope.serviceTime.getMinutes();
                if ((hours == $scope.gethours && hours == endhours && minutes >= $scope.getMinutes && minutes < endhminutes) || (hours == endhours && hours != $scope.gethours && minutes < endhminutes) || (hours == $scope.gethours && hours != endhours && minutes >= $scope.getMinutes)) {
                    $scope.grayshow = true;
                } else {
                    $scope.grayshow = false;
                }
            }
            var wraphours = $scope.serviceTime.getHours();
            var wrapminutes = $scope.serviceTime.getHours();
            if (wraphours == $scope.gethours || wraphours == endhours && wrapminutes < endhminutes) {
                countTime();
                $scope.$on('$destroy', function () {
                    $interval.cancel(intervalH)
                })
                var intervalH = $interval(function () {
                    $scope.serviceTime = new Date($scope.serviceTime.getTime() + 1000);
                    countTime();
                }, 1000)
            }
        }
        var reqstime, reqetime, reqcha;
        // 获取请求开始的时间
        reqstime = new Date().getTime();
        commonFactory.ajax('/api/UserFlexibleProduct/GetServiceTime', {}, function (result) {
            // 获取请求结束的时间
            reqetime = new Date().getTime();
            // 计算请求所用时间
            reqcha = reqetime - reqstime;
            // 后台返回的时间加上请求所用时间就是当前时间
            $scope.serviceTime = new Date(new Date(parseInt(result.data.serviceTime)).getTime() + reqcha);
            //时间段
            $scope.thistime = result.data.minute;
            //开始时间
            $scope.gethours = result.data.startTime.substring(0, 2);
            $scope.getMinutes = parseInt(result.data.startTime.substring(3, 5)) + 1;
            $scope.getSecond = parseInt(result.data.startTime.substring(6, 8));
            timeShow();
        }, function (error) {

        }, 'get')
        commonFactory.ajaxStore(options);
        $scope.productUrl = function () {//回调index
            return function (index) {
                if ($scope.producthomearr[index].productId) {
                    $rootScope.produceCode = $scope.producthomearr[index].productId
                    $rootScope.produceType = $scope.producthomearr[index].productType
                }
            }
        }
        // commonFactory.messageloading();
        //滚动手机号
        function messageSlider(ID) {
            var index = 0;
            var messageBox = document.querySelector('#' + ID);
            if (!messageBox) {
                return false
            }
            var message = messageBox.children;
            function dong() {
                if (index > message.length - 1) {
                    index = 0;
                }
                for (var i = 0; i <= message.length - 1; i++) {
                    message[i].style.top = "40px";
                }
                message[index].style.top = 0;
                index++;
            }
            dong()
            if (interval) {
                clearInterval(interval);
            }
            var interval = setInterval(dong, 3000)
        }
        $scope.dataover = function (last) {//数据加载完成执行向上滚动
            if (last) {
                $timeout(function () { messageSlider('message') }, 50)
            }
        }

        commonFactory.ajax("/api/Product/GetNewBuyNote", {}, function (result) {
            if (result.code == 1) {
                $scope.newBuyNote = result.data;
            } else if (result.code == 2) {
                commonFactory.messageshow({ content: "<div class='bg_tan'>查询失败</div>" });
            }
        }, function () {
            commonFactory.messageshow({ content: "<div class='bg_tan'>后台错误</div>" });
        }, "post");
        //交易总额
        var GetTransactionData = CacheFactory.getStorage("time_GetTransactionData");
        if (GetTransactionData) {
            $scope.GetTransactionData = GetTransactionData
        }
        commonFactory.ajax("/api/Product/GetTransactionData", {}, function (result) {
            if (result.code == 1) {
                $scope.GetTransactionData = result.data;
                CacheFactory.setStorage("time_GetTransactionData", result.data, { isExpires: true, expiresTime: CacheFactory.hour * 48 });
            } else if (result.code == 2) {
                commonFactory.messageshow({ content: "<div class='bg_tan'>查询失败</div>" });
            }
        }, function () {
            commonFactory.messageshow({ content: "<div class='bg_tan'>后台错误</div>" });
        }, "post");
    }
    //广告
    if ($rootScope.showappad == true || $rootScope.showappad == false) {

    } else {
        $rootScope.showappad = true;
    }
    var getInitAd = function () {
        $rootScope.showappad = false;
        commonFactory.ajax("/api/Ad/AdList", { typeid: 2, num: 1 }, function (result) {
            loadingArr.push("AdList");
            if (result.code == 1) {
                if (result.data && result.data.length > 0) {
                    for (var i = result.data.length - 1; i >= 0; i--) {
                        if (result.data[i].adImage && result.data[i].adImage != "") {
                            if (result.data[i].adImage.indexOf("http://") == -1 && result.data[i].adImage.indexOf("https://") == -1) {
                                result.data[i].adImage = $rootScope.imgbaseurl + result.data[i].adImage;
                            }
                        }
                    }
                    var sourcedata = result.data[0];
                    if (sourcedata.adImage) {
                        $scope.adhtml = "<div class=\"is_ad\">";
                        $scope.adhtml += "<i class=\"is_ad_i_cha pull-right\" activeclass=\"ng-nobgm\" ng-click=\"closelayout($event)\"></i>";
                        $scope.adhtml += "<img src=\"" + sourcedata.adImage + "\" activeclass=\"ng-nobgm\" ng-click=\"othergo('" + sourcedata.adUrl + "')\">";
                        $scope.adhtml += "</div>";
                    }
                }
            }
        }, null, "post");
    }
    if ($rootScope.showappad) {
        loadingCount = loadingCount + 1;
    }

    $timeout(function () {
        uranusiscroll.refresh();
    }, appconfig.pulldowntime);
    if ($rootScope.showappad) {
        getInitAd();
    }
    $scope.closelayout = function (e) {
        commonFactory.messageclose();
    }

    initdata()
}]);
/* 产品 */
UranusWei.controller("mainlist", ['$scope', '$rootScope', 'uranusiscroll', 'commonFactory', 'appconfig', '$timeout', 'CacheFactory', '$interval', 'uranusPlus', function ($scope, $rootScope, uranusiscroll, commonFactory, appconfig, $timeout, CacheFactory, $interval, uranusPlus) {
    $rootScope.Template = {
        title: '月月赚',
        state: 'mainlist',
        showbackicon: false,
        showheader: true
    }
    var dthis = new uranusiscroll();
    var text = commonFactory.GetRandomPullAd();
    dthis.showtext({ downtext: text, opentext: text, loadingtext: text });
    uranusiscroll = dthis.init(true, false);
    uranusiscroll.pullDownAction = function () {
        text = commonFactory.GetRandomPullAd();
        dthis.showtext({ downtext: text, opentext: text, loadingtext: text });
        $timeout(function () {
            uranusiscroll.refresh();
            initdata()
        }, appconfig.pulldowntime);
    }
    // CacheFactory.setStorage('getWeal', '');
    function drawarc(percent, ctx, sR) {
        if (percent < 0 || percent > 100) {
            return;
        }
        if (sR < Math.PI / 2 || sR >= 3 / 2 * Math.PI) {
            return;
        }
        var canvas = ctx,
            cxt = canvas.getContext('2d'),
            cWidth = canvas.width,
            cHeight = canvas.height,
            baseColor = '#fff1ef',
            coverColor = '#ff6c64',
            txtcolor = '#ff6c64',
            PI = Math.PI,
            sR = sR || 1 / 2 * PI; // 默认圆弧的起始点弧度为π/2
        var finalRadian = sR + ((PI + (PI - sR) * 2) * percent / 100); // 红圈的终点弧度
        var step = (PI + (PI - sR) * 2) / 100; // 一个1%对应的弧度大小
        var text = 0;

        window.requestAnimationFrame(paint);
        w = window.innerWidth * 0.12 / 2;
        function paint() {
            cxt.clearRect(0, 0, cWidth, cHeight);
            var endRadian = sR + text * step; //动画起始位置
            var lGrd = cxt.createLinearGradient(endRadian, endRadian, 0, cHeight);
            // lGrd.addColorStop(0, coverColor);
            // lGrd.addColorStop(0.3, coverColor);
            lGrd.addColorStop(1, coverColor);
            // 画灰色圆弧
            drawCanvas(cWidth / 2, cHeight / 2, w * 2, sR, sR + (PI + (PI - sR) * 2), baseColor, 8);
            // 画蓝色圆弧
            drawCanvas(cWidth / 2, cHeight / 2, w * 2, -sR, endRadian - sR * 2, lGrd, 8);

            cxt.fillStyle = txtcolor;
            cxt.font = '24px PT Sans';
            var textWidth = cxt.measureText('抢').width;
            cxt.fillText('抢', cWidth / 2 - textWidth / 2, cHeight / 2 + 9);
            text++;
            if (endRadian.toFixed(2) < finalRadian.toFixed(2)) {
                window.requestAnimationFrame(paint);
            }
        }
        function drawCanvas(x, y, r, sRadian, eRadian, color, lineWidth) {
            cxt.beginPath();
            cxt.lineCap = "round";
            cxt.strokeStyle = color;
            cxt.lineWidth = lineWidth;
            cxt.arc(x, y, r, sRadian, eRadian, false);
            cxt.stroke();
        }
    }

    var initdata = function () {
        var loadingArr = [], loadingCount = 1;
        commonFactory.initComplate(loadingArr, loadingCount, function () {
            if (appconfig.version >= $rootScope.webversion) {//当版本切换时 广告弹框关闭
                commonFactory.messageclose();
            }
        });
        $scope.ctxwidth = window.innerWidth * 0.136 + 8
        var cache_productlist = CacheFactory.getStorage("time_productlist");
        if (cache_productlist) {
            $scope.list = cache_productlist;
            for (var i = 0; i < cache_productlist.length; i++) {
                cache_productlist[i].ServerTime = null;
            }
            loadingArr.push("GetProductList");
            $timeout(function () {
                uranusiscroll.refresh();

            }, 300);
        } else {
            commonFactory.messageloading({ process: true });
        }
        // 获取月月赚列表数据
        commonFactory.ajax("/api/UserProduct/QueryProductList", {}, function (result) {
            if (!cache_productlist) {
                loadingArr.push("GetProductList");
            }
            if (result.code == 1) {
                var data = result.data;
                for (var i = 0; i < data.length; i++) {
                    data[i].ServerTime = null;
                }

                // $timeout(drawy, 300);
                if (!commonFactory.comparisonobj(data, cache_productlist)) {
                    $scope.list = data;
                    CacheFactory.setStorage("time_productlist", data, { isExpires: true, expiresTime: CacheFactory.day * 1 });
                    $timeout(function () {
                        uranusiscroll.refresh()
                    }, 300);
                }
            }
        }, function () {
            if (!cache_productlist) {
                loadingArr.push("GetProductList");
            }
        }, "post");
    }

    initdata();

    function drawy() {//优化动画
        var lineColor = document.querySelectorAll(".list_canvas"); //获取元素数组
        for (i = 0; i < lineColor.length; i++) {
            if ($scope.list[i] && lineColor[i]) {
                CurrentWidth1 = $scope.list[i].currentSchedule * 100;
                if (CurrentWidth1 < 100) {
                    if (CurrentWidth1 >= 97 && CurrentWidth1 < 100) {
                        CurrentWidth1 = 96;
                    }
                    drawarc(CurrentWidth1.toFixed(0), lineColor[i])
                } else {
                    i = i//已回款的标 购买总金额为0（currentLoanPrice ） 出现两个图标重叠现象
                }

            } else {
                return false;
            }
        }
    }
    $scope.initDatas = function (last) {
        if (last) {
            $timeout(drawy, 30);
        }
    }

}]);
/* 个人中心 */
UranusWei.controller("mainmine", ['$scope', '$rootScope', 'uranusiscroll', 'commonFactory', 'appconfig', '$timeout', 'CacheFactory', 'uranusPlus', function ($scope, $rootScope, uranusiscroll, commonFactory, appconfig, $timeout, CacheFactory, uranusPlus) {
    $rootScope.Template = {
        title: '个人中心',
        state: 'mainmine',
        showbackicon: false,
        showheader: false
    }
    var loadingArr = [], loadingCount = 1;
    var dthis = new uranusiscroll();
    var text = commonFactory.GetRandomPullAd();
    dthis.showtext({ downtext: text, opentext: text, loadingtext: text });
    uranusiscroll = dthis.init(false, false);
    $scope.testloginout = function () {
        commonFactory.loginout();
    }
    commonFactory.initComplate(loadingArr, loadingCount, function () {
        if (appconfig.version >= $rootScope.webversion) {//当版本切换时 广告弹框关闭
            commonFactory.messageclose();
        }
    });
    $scope.goshare = function () {
        commonFactory.ajax("/api/Share/MyShareStatistics", {}, function (result) {
            if (result.code == 1) {
                if (result.data.bonuses && result.data.firends || result.data.bonuses) {
                    commonFactory.go('/mine/invitebonus/bonusdetail')
                } else if (result.data.firends) {
                    commonFactory.go('/mine/invitebonus/friendlist')
                } else {
                    commonFactory.go('/mine/invitebonus/bonusdetail')
                }
            } else if (result.code == 8) {
                commonFactory.gologin();
            }
        }, function () {

        }, "post");
    }
    $scope.userinfo = {
        PredictEarning: 0,
        UsablePrice: 0,
        InvestingPrice: 0
    }
    function create() {
        var w = plus.webview.create(appconfig.baseurladd + '/setting/bindcard', 'outbankcard', { height: '100%', width: '100%' });
        var ws = plus.webview.currentWebview();
        w.setStyle({ data: 2 });// 子
        ws.append(w);
        w.show(); // 显示窗口
        function evajs() {
            w.evalJS('if(document.getElementsByTagName("body")[0].innerText.indexOf("汇付天下")!=-1){plus.webview.currentWebview().setStyle({data:"success"})}else{plus.webview.currentWebview().setStyle({data:"error"})}')
        }
        w.onloaded = function () {
            if (w.getTitle() == '汇付天下') {
                var ws = plus.webview.currentWebview();
                ws.append(w);
                var clear = setInterval(function () {
                    if (w.getStyle().data == 2) {
                        evajs()
                    } else {
                        clearInterval(clear);
                    }
                    $scope.mydata = w.getStyle().data;
                    closeweb()
                }, 100);
            }
        }
        function closeweb() {
            if ($scope.mydata == "error") {
                plus.webview.close('outbankcard');
                $timeout(function () {
                    commonFactory.go('/main/mine');
                    $timeout(function () { commonFactory.messageshow({ content: "<div class='bg_tan'>交易密码输入有误，请重新输入</div>" }); }, 200)//输入密码错误或者没输入 跳转我的页面并提示
                }, 10)
            } else if ($scope.mydata == "success") {
                var ws = plus.webview.currentWebview();
                w.setCssText('body{display:block}');
                ws.append(w);
                $timeout(function () {
                    plus.webview.close('outbankcard');
                    $timeout(function () { commonFactory.go('/main/mine'); }, 10)//跳转我的页面
                }, 2000)
            }
        }
    }
    $scope.closelayout = function () {
        commonFactory.messageclose();
    }
    $scope.goWhere = function (event) {
        commonFactory.ajax("/api/user/getuserinfo", {}, function (result) {
            if (result.code == 1) {
                if (result.data.userId <= 0) {
                    commonFactory.gologin();
                    return;
                }
                var data = result.data;
                if (data.usrCustId == null || !data.usrCustId) {
                    CacheFactory.setStorage('time_comebackUrl', '/main/mine', { isExpires: true, expiresTime: CacheFactory.hour * 1 })//设置开户回调地址
                    // commonFactory.go("/mine/realname");
                    commonFactory.ajax("/api/bank/gettime", {}, function (result) {
                        if (result.code == 1) {
                            commonFactory.messageclose();
                            var severseTime = new Date(new Date(result.data.replace(/-/g, '/')).getTime()); //服务器时间
                            var nhours = severseTime.getHours();
                            var nminutus = severseTime.getMinutes();
                            if (nhours >= 1 && nhours <= 5) {
                                var html = '<div id="js_singlePrice">';
                                html += '       <section class="withtan_box">';
                                html += '           <p class="clearfix witht_b_tit">';
                                html += '               <span class="text_center">&nbsp;提示</span>';
                                html += '               <span class="pull-right with_b_t_icon" ng-click="closelayout()"></span>';
                                html += '           </p>';
                                html += '           <div class="withtan_content">';
                                html += '               <div class="clearfix with_c_div" style="padding-bottom:1.0667rem">';
                                html += '                   为了保障用户资金安全，平台1:00--5:00为银行对账时段，暂停汇付天下账户开通，请您稍后操作。感谢您的理解与支持。';
                                html += '               </div>';
                                html += '               <div class="withtan_content_bth with_c_p_but_color" ng-click="closelayout()">';
                                html += '                   我知道了';
                                html += '               </div>';
                                html += '           </div>';
                                html += '       </section>';
                                html += '   </div>';
                                commonFactory.messageview(html, { width: 1, height: 1 }, $scope);
                            } else {
                                commonFactory.go('/mine/realname')
                            }
                        }
                    }, function () { }, 'post')

                    return
                } else {
                    if (event.target.innerText == "充值") {
                        commonFactory.go("/mine/recharge");
                    } else if (event.target.innerText == "提现") {
                        if (!data.bankCard || data.bankCard == null) {
                            if (uranusPlus.isApp) {
                                create();//app创建webveiw
                            } else {
                                //跳转汇付天下绑卡
                                commonFactory.ajax("/api/user/UserBindCard", {}, function (result) {
                                    if (result.code == 1) {
                                        $scope.html = "";
                                        $scope.html += '<form name="form" id="bindbankform" method="post" action="' + appconfig.hfurl + '">';
                                        for (var i in result.data) {//动态编译form
                                            res = i.substring(0, 1).toUpperCase() + i.substring(1);//处理name值首字母大写
                                            if (result.data[i] == null) {//参数值为null处理为空字符串
                                                result.data[i] = '""';
                                            }
                                            $scope.html += '<input name="' + res + '" id="' + res + '" type="hidden" value=' + result.data[i] + ' />';
                                        }
                                        $scope.html += '</form>';
                                        $timeout(function () {
                                            var bindbankform = document.querySelector('#bindbankform')
                                            bindbankform.submit();
                                        }, 50)
                                    } else if (result.code == 3) {
                                        commonFactory.messageshow({ content: "<div class='bg_tan'>" + result.data + "</div>" })
                                    } else {
                                        commonFactory.messageshow({ content: "<div class='bg_tan'>后台系统异常</div>" });
                                    }
                                }, function () {
                                    commonFactory.messageshow({ content: "<div class='bg_tan'>error</div>" });
                                }, "post");

                            }
                        } else {
                            commonFactory.go("/mine/withdrawals");
                        }
                    }
                }
            } else if (result.code == 8) {
                commonFactory.gologin();
            } else {
                commonFactory.messageshow({ content: "<div class='bg_tan'>获取用户信息失败</div>" });
            }
        }, function () {
            commonFactory.messageshow({ content: "<div class='bg_tan'>获取用户信息失败</div>" });
        }, "post");
    }

    var initdata = function () {
        var time_canoffer = CacheFactory.getStorage("time_canoffer")
        if (time_canoffer) {
            $scope.querycanoffer = time_canoffer
        }
        commonFactory.ajax("/api/user/QueryCanOffer", {}, function (result) {
            if (result.code == 1) {
                $scope.querycanoffer = result.data;
                CacheFactory.setStorage("time_canoffer", result.data, { isExpires: true, expiresTime: CacheFactory.day * 1 });
            }
        }, function () {

        }, "post");
        var time_mineprice = CacheFactory.getStorage("time_mineprice")
        if (time_mineprice) {
            $scope.userinfoprice = time_mineprice
        }
        commonFactory.ajax("/api/price/myprice", {}, function (result) {
            if (result.code == 1) {
                var data = result.data;
                CacheFactory.setStorage("time_mineprice", data, { isExpires: true, expiresTime: CacheFactory.day * 1 });
                $scope.userinfoprice = data;
            } else if (result.code == 8) {
                commonFactory.gologin();
            }
        }, function () {

        }, "post");
        commonFactory.ajax("/api/Notice/GetUserNoticeReadInfo", {}, function (result) {
            if (result.code == 1) {
                $scope.GetUserNoticeReadInfo = result.data;
            } else {
                commonFactory.messageshow({ content: "<div class='bg_tan'>后台无返回值</div>" })
            }
        }, function () {
            commonFactory.messageshow({ content: "<div class='bg_tan'>后台错误</div>" })
        }, "post");
    }
    initdata();
}]);
/**安全保障 */
UranusWei.controller("safety", ['$scope', '$rootScope', 'uranusiscroll', 'commonFactory', 'appconfig', '$timeout', 'CacheFactory', '$location', '$window', 'translider', function ($scope, $rootScope, uranusiscroll, commonFactory, appconfig, $timeout, CacheFactory, $location, $window, translider) {
    var linkurl = ''
    if ($rootScope.previousState && ($rootScope.previousState.url == '/home' || $rootScope.previousState.url == '/mine/more')) {
        if ($rootScope.previousState.url == '/home') {
            linkurl = '/main' + $rootScope.previousState.url;
        } else {
            linkurl = $rootScope.previousState.url;
        }

    }
    $rootScope.Template = {
        title: '安全保障',
        state: 'morecommon',
        showbackicon: true,
        showheader: true,
        backlink: linkurl
    }
    var dthis = new uranusiscroll();
    uranusiscroll = dthis.init(false, false);
    document.ondragstart = function () { return false; }		//禁止拖拽页面图片
    var _mouseDown = false,								//滑动事件是否开始
        num = 0,											//当前页面的Index数
        h = document.body.offsetHeight,							//页面的高度
        $content = document.getElementById('content'),	//事件包裹的大标签
        $page = $content.getElementsByClassName('page'),								//事件切换的标签
        leng = $page.length;								//切换标签的个数			

    for (var i = 0; i < leng; i++) {
        var Classname = $page[i].getAttribute('class');
        $page[i].setAttribute('data-class', Classname);
        $page[i].style.height = h + 'px';				//给事件切换的标签加上与屏幕相同的高度
    }

    //绑定事件
    document.addEventListener('mousedown', touchSatrtFunc, false); 	//触摸事件
    document.addEventListener('mousemove', touchMoveFunc, { passive: false }); 	//滑动事件
    document.addEventListener('mouseup', touchEndFunc, false); 		//离开元素事件
    document.addEventListener('touchstart', touchSatrtFunc, false); 	//触摸事件
    document.addEventListener('touchmove', touchMoveFunc, false); 	//滑动事件
    document.addEventListener('touchend', touchEndFunc, false); 		//离开元素事件

    //触摸事件开始
    function touchSatrtFunc(e) {
        //触摸开始时需要设置触摸点与滑动的距离为0。

        startY = 0;        //触摸点
        endY = 0;          //滑动的距离

        //因为绑定多个事件支持手机电脑、所以判断当前触发的效果而获取不同的值。
        if (e.type == 'touchstart') {
            var touch = window.event.touches[0].pageY;
        } else {
            var touch = e.pageY || e.y;
        }
        _mouseDown = true;		//设置开启滑动事件
        var y = Number(touch); //页面触点Y坐标  
        $content.className = 'content';		//给父级加上class、使其在拖拽时添加content而覆盖原有的属性、
        //记录触点初始位置  
        startY = y;
    }

    //滑动事件开始
    function touchMoveFunc(e) {
        // e.preventDefault()	//阻止触摸时浏览器的缩放、滚动条滚动等

        if (e.type == 'touchmove') {
            var touch = window.event.touches[0].pageY;
        } else {
            var touch = e.pageY || e.y;
        }
        var y = Number(touch),
            _top = $content.getAttribute('data-y');				//获取当前页面的data-y值

        endY = y;

        //滑动过程中当前页面跟随滑动
        if (_mouseDown == true) {
            if (startY - endY > 0) {
                $content.style.WebkitTransform = 'translate3d(0,' + (endY - startY - _top) + 'px,0)';
                $content.style.transform = 'translate3d(0,' + (endY - startY - _top) + 'px,0)';
            } else {
                $content.style.WebkitTransform = 'translate3d(0,' + (-startY + endY - _top) + 'px,0)';
                $content.style.transform = 'translate3d(0,' + (-startY + endY - _top) + 'px,0)';
            }
        }
    }
    //离开元素事件  
    function touchEndFunc(e) {
        $timeout(function () {
            uranusiscroll.refresh();
        }, appconfig.pulldowntime);
        _mouseDown = false;			//关闭滑动事件

        $content.className = '';	//给父级删除class、使其恢复原先属性、

        //判断滑动的距离以及滑动的方向来判断是否进入到下一个页面
        if (startY - endY > 50 && startY - endY != startY) {
            //判断是否是最后一页、如是最后一页时不再向下滑动。
            if (num >= leng - 1) {

                $content.style.WebkitTransform = 'translate3d(0,' + -num * h + 'px,0)';
                $content.style.transform = 'translate3d(0,' + -num * h + 'px,0)';
            } else {
                num++;
                if (num == 6) {//向上按钮
                    $scope.num = true;
                } else {
                    $scope.num = false
                }
                $content.style.WebkitTransform = 'translate3d(0,' + -num * h + 'px,0)';
                $content.style.transform = 'translate3d(0,' + -num * h + 'px,0)';
            }
            for (var i = 0; i < leng; i++) {
                var Classname = $page[i].getAttribute('data-class');
                $page[i].className = Classname;
            }
            var Classname = $page[num].getAttribute('data-class');
            $page[num].className = Classname + ' animate';
            $content.setAttribute('data-y', num * h);
        } else if (endY - startY > 50) {
            //判断是否是第一页、如是第一页时不再向上滑动。
            if (num <= 0) {
                $content.style.WebkitTransform = 'translate3d(0,' + -num * h + 'px,0)';
                $content.style.transform = 'translate3d(0,' + -num * h + 'px,0)';
            } else {
                num--;
                if (num == 6) {//向上按钮
                    $scope.num = true;
                } else {
                    $scope.num = false
                }
                $content.style.WebkitTransform = 'translate3d(0,' + -num * h + 'px,0)';
                $content.style.transform = 'translate3d(0,' + -num * h + 'px,0)';
            }
            for (var i = 0; i < leng; i++) {
                var Classname = $page[i].getAttribute('data-class');
                $page[i].className = Classname;
            }
            var Classname = $page[num].getAttribute('data-class');
            $page[num].className = Classname + ' animate';
            $content.setAttribute('data-y', num * h);
        } else {
            //未切换
            $content.style.WebkitTransform = 'translate3d(0,' + -num * h + 'px,0)';
            $content.style.transform = 'translate3d(0,' + -num * h + 'px,0)';
        }
    }
    $scope.clickNext = function () {
        //判断是否是最后一页、如是最后一页时不再向下滑动。
        if (num >= leng - 1) {
            $content.style.WebkitTransform = 'translate3d(0,' + -num * h + 'px,0)';
            $content.style.transform = 'translate3d(0,' + -num * h + 'px,0)';
        } else {
            num++;
            if (num == 6) {//向上按钮
                $scope.num = true;
            } else {
                $scope.num = false
            }
            $content.style.WebkitTransform = 'translate3d(0,' + -num * h + 'px,0)';
            $content.style.transform = 'translate3d(0,' + -num * h + 'px,0)';
        }
        for (var i = 0; i < leng; i++) {
            var Classname = $page[i].getAttribute('data-class');
            $page[i].className = Classname;
        }
        var Classname = $page[num].getAttribute('data-class');
        $page[num].className = Classname + ' animate';
        $content.setAttribute('data-y', num * h);
    }
    $scope.clickPrev = function () {
        //判断是否是第一页、如是第一页时不再向上滑动。
        if (num <= 0) {
            $content.style.WebkitTransform = 'translate3d(0,' + -num * h + 'px,0)';
            $content.style.transform = 'translate3d(0,' + -num * h + 'px,0)';
        } else {
            num--;
            if (num == 6) {//向上按钮
                $scope.num = true;
            } else {
                $scope.num = false
            }
            $content.style.WebkitTransform = 'translate3d(0,' + -num * h + 'px,0)';
            $content.style.transform = 'translate3d(0,' + -num * h + 'px,0)';
        }
        for (var i = 0; i < leng; i++) {
            var Classname = $page[i].getAttribute('data-class');
            $page[i].className = Classname;
        }
        var Classname = $page[num].getAttribute('data-class');
        $page[num].className = Classname + ' animate';
        $content.setAttribute('data-y', num * h);
    }
    //当浏览器窗口发生改变时重新定义
    window.onresize = function () {
        h = document.body.offsetHeight;
        $content.setAttribute('data-y', num * h);
        $content.style.WebkitTransform = 'translate3d(0,' + -num * h + 'px,0)';
        $content.style.transform = 'translate3d(0,' + -num * h + 'px,0)';
        for (var i = 0; i < leng; i++) {
            $page[i].style.height = h + 'px';
        }
    }
}]);
/* 热门活动 */
UranusWei.controller("hotactives", ['$scope', '$rootScope', 'uranusiscroll', 'commonFactory', 'appconfig', '$timeout', 'CacheFactory', '$location', '$window', 'translider', function ($scope, $rootScope, uranusiscroll, commonFactory, appconfig, $timeout, CacheFactory, $location, $window, translider) {
    $rootScope.Template = {
        title: '热门活动',
        state: 'hotactives',
        showbackicon: true,
        showheader: true,
        backlink: "/main/home"
    }
    var dthis = new uranusiscroll();
    var text = commonFactory.GetRandomPullAd();
    dthis.showtext({ downtext: text, opentext: text, loadingtext: text });
    uranusiscroll = dthis.init(false, true);
    var pathName = location.pathname;
    /* 上拉加载 */
    uranusiscroll.pullUpAction = function () {
        getinvestmentlist();
    }
    $scope.showpullup = false;//默认隐藏上啦加载
    var cache_pularslist;
    var loadingArr = [], loadingCount = 2;
    var index = 1, size = 5;
    $scope.isloaded = false;

    var initdata = function () {
        commonFactory.initComplate(loadingArr, loadingCount, function () {
            $timeout(function () {
                uranusiscroll.refresh();
            }, appconfig.pulldowntime);
        });

        /* 读取热门活动列表缓存 */
        cache_pularslist = CacheFactory.getStorage("user_dqinvestmentlist1");
        if (cache_pularslist) {
            loadingArr.push("dqinvestmentlist");
            $scope.pularslist = cache_pularslist;
            $scope.isload = true;
        }
        getinvestmentlist();
    }
    var getinvestmentlist = function (isload) {
        if (isload) {
            commonFactory.messageloading();
        }
        // 月月赚账户持有中已回款列表请求（done：false持有中，true已回款）
        commonFactory.ajax("/api/Ad/QueryPopulars", { index: index, size: size }, function (result) {
            $scope.isloaded = true;
            if (isload) {
                commonFactory.messageclose();
            }
            if (!cache_pularslist) {
                loadingArr.push("GetPopularsList");
            }
            if (result.code == 1) {
                var data = result.data.dtos;
                for (var j = data.length - 1; j >= 0; j--) {
                    if (data[j].adImage && data[j].adImage != "") {
                        if (data[j].adImage.indexOf("http://") == -1 && data[j].adImage.indexOf("https://") == -1) {
                            data[j].adImage = $rootScope.imgbaseurl + data[j].adImage;
                        }
                    }
                }
                if (data) {
                    //没有数据
                    if (index == 1 && data.length == 0) {
                        uranusiscroll.isOverData = true;
                    } else {
                        cache_pularslist = data;
                        if (index == 1 || !$scope.pularslist) {
                            CacheFactory.setStorage("user_pularslist", cache_pularslist);
                            $scope.pularslist = cache_pularslist;
                        } else {
                            $scope.pularslist = $scope.pularslist.concat(cache_pularslist);
                        }
                        $timeout(function () {
                            uranusiscroll.refresh();
                        }, appconfig.pulldowntime);
                        if (data.length != size) { //如果没有数据了
                            uranusiscroll.isOverData = true;
                            if (index == 1) { //数据在一页读完

                            } else {
                                $scope.showpullup = true;
                            }
                        } else {
                            index++;
                            $scope.showpullup = true;
                        }
                    }
                } else if (result.code == 8) {
                    commonFactory.gologin();
                }
            }
        }, function () {
            $scope.isloaded = true;
            if (isload) {
                commonFactory.messageclose();
            }
            if (!cache_pularslist) {
                loadingArr.push("GetPopularsList");
            }
            $timeout(function () {
                uranusiscroll.refresh();
            }, appconfig.pulldowntime);

        }, "post");
    }
    initdata();
}]);
/**新手专享 */
UranusWei.controller("newactivity", ['$scope', '$rootScope', 'uranusiscroll', 'commonFactory', 'appconfig', '$timeout', 'CacheFactory', '$location', '$window', 'translider', function ($scope, $rootScope, uranusiscroll, commonFactory, appconfig, $timeout, CacheFactory, $location, $window, translider) {
    $rootScope.Template = {
        title: '新手专享',
        state: 'newactivity',
        showbackicon: true,
        showheader: true,
        backlink: "/home/hotactives"
    }
    var dthis = new uranusiscroll();
    uranusiscroll = dthis.init();
    var getuser = CacheFactory.getUser()
    $scope.newactivity = function () {
        if (getuser && CacheFactory.getUser().userKey) {
            commonFactory.go('/mine/youliweal/experience')
        } else {
            commonFactory.go('/register/index')
        }
    }
    $scope.gonewdetail = function () {
        commonFactory.ajax("/api/product/GetHdProductList", { pageindex: 1, pagesize: 10 }, function (result) {
            if (result.code == 1) {
                var data = result.data;
                for (var i = 0; i < data.length; i++) {
                    if (data[i].loanPeriod == 5) {
                        commonFactory.go('/product/' + data[i].id);
                    }
                }
            }
        }, function () {

        }, "post");
    }

}]);